﻿using System;
using System.Reflection;
using System.Windows.Forms;

using Pegasus.Diagnostics.Contracts;

namespace Pegasus.Windows.Forms
{
	/// <summary>
	/// This class is used to display an information box to the user.
	/// </summary>
	public static class InfoBox
	{
		// Local Static Values
		private static string s_caption = "Information";

		/// <summary>
		/// Initializes the <see cref="InfoBox"/> class.
		/// </summary>
		static InfoBox()
		{
			try
			{
				s_caption = Assembly.GetEntryAssembly().GetName().Name.Trim();
			}
			catch
			{
			}
		}

		/// <summary>
		/// Gets or sets the default caption.
		/// </summary>
		/// <value>The default caption.</value>
		public static string Caption
		{
			get
			{
				return s_caption;
			}

			set
			{
				Contract.Requires( !string.IsNullOrEmpty( value ), "Caption can not be null or empty" );
				s_caption = value;
			}
		}

		/// <summary>
		/// Shows the specified message in an information message box.
		/// </summary>
		/// <param name="message">The message.</param>
		public static void Show( string message )
		{
			Contract.Requires( !string.IsNullOrEmpty( message ), "Message can not be null or empty" );

			Show( null, message, s_caption );
		}

		/// <summary>
		/// Shows the specified message in an information message box.
		/// </summary>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		public static void Show( string message, string caption )
		{
			Contract.Requires( !string.IsNullOrEmpty( message ), "Message can not be null or empty" );

			Show( null, message, caption );
		}

		/// <summary>
		/// Shows the specified message in an information message box.
		/// </summary>
		/// <param name="parent">The parent window or form.</param>
		/// <param name="message">The message.</param>
		public static void Show( IWin32Window parent, string message )
		{
			Contract.Requires( !string.IsNullOrEmpty( message ), "Message can not be null or empty" );

			Show( parent, message, s_caption );
		}

		/// <summary>
		/// Shows the specified message in an information message box.
		/// </summary>
		/// <param name="parent">The parent window or form.</param>
		/// <param name="message">The message.</param>
		/// <param name="caption">The caption.</param>
		public static void Show( IWin32Window parent, string message, string caption )
		{
			Contract.Requires( !string.IsNullOrEmpty( message ), "Message can not be null or empty" );

			MessageBox.Show( parent, message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information );
		}
	}
}
